/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ex3;

/**
 *
 * @author Gu
 */
public class Main
{
    public static void main(String[] args)
    {
        int[] a = {5, 2, 7, 16, 9, 64, 35, 79, 96, 28};

        getMinMax1(a);

       
    }

    public static void getMinMax1(int[] a)
    {
        int min = 0;
        int max = 0;

        min = a[0];
        max = a[0];

        for(int i=1; i<a.length-1; i++)
        {
            if(a[i] < min)
                min = a[i];

            if(a[i] > max)
                max = a[i];
        }

        System.out.println("Method 1");
        System.out.println("min value is : " + min);
        System.out.println("max value is : " + max);
    }

    public static void getMinMax2(int[] a)
    {
        int index = 0;
        int min = 0;
        int max = 0;

        if(a.length % 2 == 0)
        {
            if(a[0] <= a[1])
            {
                min = a[0];
                max = a[1];
            }
            else
            {
                min = a[1];
                max = a[0];
            }

            index = 2;
        }
        else
        {
            min = a[0];
            max = a[0];

            index = 1;
        }

        for(int i=index; i<a.length-1; i++)
        {
            if(a[i] <= a[i+1])
            {
                if(a[i] < min)
                    min = a[i];

                if(a[i+1] > max)
                    max = a[i+1];
            }
            else
            {
                if(a[i+1] < min)
                    min = a[i+1];

                if(a[i] > max)
                    max = a[i];
            }
        }

        System.out.println("Method 2");
        System.out.println("min value is : " + min);
      
    }
}
